﻿using Microsoft.Extensions.Options;
using NumericUpDownLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using XYAC.Framework.MonitorTireMaterialManual.Extensions;
using XYAC.Framework.MonitorTireMaterialManual.ViewModels;

namespace XYAC.Framework.MonitorTireMaterialManual.Views.ReadonlyView
{
    /// <summary>
    /// SemiSteelTriangleRubberView.xaml 的交互逻辑
    /// </summary>
    public partial class SemiSteelTriangleRubberReadonlyView : UserControl
    {
        public IOptionsMonitor<AppConfig> AppConfig { get; }
        public SemiSteelTriangleRubberViewModel ViewModel { get; }

        private IServiceProvider provider;

        public SemiSteelTriangleRubberReadonlyView(IOptionsMonitor<AppConfig> appConfig, SemiSteelTriangleRubberViewModel viewmodel, IServiceProvider provider)
        {
            this.DataContext = this.ViewModel = viewmodel;
            this.ViewModel.CloseWindow = () =>
            {
                if (this.Parent is Window win)
                {
                    win.DialogResult = true;
                    win.Close();
                }
            };
            this.AppConfig = appConfig;
            this.provider = provider;
            InitializeComponent();
        }




        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (sender is ComboBox cmb)
            {
                if (cmb.SelectedIndex != -1)
                    this.ViewModel.CrossSectionShape = (cmb.SelectedItem as ComboBoxItem).Tag.ToString();
            }

        }

        internal void ClearViewModelValue()
        {
            this.ViewModel.SemiSteelTriangleRubberReport = null;
        }

        private void FloatUpDown_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (sender is FloatUpDown np)
            {
                if (np.IsReadOnly)
                {
                    np.IsReadOnly = false;
                    np.IsIncDecButtonsVisible = true;
                }
            }
        }

        private void FloatUpDown_KeyDown(object sender, KeyEventArgs e)
        {
            if (sender is FloatUpDown np && (e.Key == Key.Enter || e.Key == Key.Escape))
            {
                np.IsReadOnly = true;
                np.IsIncDecButtonsVisible = false;
            }

        }
    }
}
